<?php
namespace app\admin\logic;
use think\Model;
use app\admin\model\Menu as MenuModel;
class Menu extends MenuModel
{
	protected $result;

	protected function initialize()
	{
		//先继承父级初始参数
		parent::initialize();

		//结果集
		$this->result ['bool']			= false;	//成功 true  失败 false
		$this->result ['code']  		= 0;		//消息代号
		$this->result ['message']  		= '';		//消息
		$this->result ['data']  		= array();	//数据结果
	}


	public function dataList($map='', $order='ID DESC', $limit=10)
	{
		return $this->lists($map, $order, $limit);
	}

	public function dataFind($id)
	{
		$res = $this->one($id);
		if($res == 'notexist') {
			$this->result ['code'] = $res;
			return $this->result;
		}
		$this->result ['bool'] = true;
		$this->result ['data'] = $res;
		return $this->result;
	}

	public function dataAdd($data)
	{
		$res = $this->updates($data);
		if($res < 1) {
			$this->result ['code'] = $res;
			return $this->result;
		}
		$this->result ['bool'] = true;
		return $this->result;
	}

	public function dataUpdate($data, $id)
	{

		if( empty($data) ) {
			$this->result ['code'] = -10005;
			return $this->result;
		}

		if( empty($id) ) {
			$this->result ['code'] = 'param';
			return $this->result;
		}

		$res = $this->updates($data, $id);

		if( $res >= 1 ) {
			$this->result ['bool'] = true;
		} else {
			$this->result ['code'] = $res;
		}
		return $this->result;
	}

	public function getPidMenu($pid=0)
	{
		//ID 标题
		$field = 'id, title';

		$map ['pid'] = $pid;

		return db('menu')->field($field)->where($map)->order('sort DESC')->select();
	}
	/**
	 * 获取左侧菜单
	 * @author 鬼谷子 <majianwei168@outlook.com>
	 * @DateTime 2017-02-28T21:39:34+0800
	 * @return   array                   菜单数据
	 */
	public function getMenu()
	{
		
	}

}